//
//  MainViewController.m
//  Student
//
//  Created by 马腾飞 on 15/9/8.
//  Copyright (c) 2015年 XueYinYue. All rights reserved.
//

#import "MainViewController.h"
#import "RDVTabBarItem.h"
#import "HomePageViewController.h"
#import "LearnMusicViewController.h"
#import "MusicCircleViewController.h"
#import "MineViewController.h"

@interface MainViewController ()<RDVTabBarControllerDelegate>

@end

@implementation MainViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.delegate = self;
    
    [self initTabBar];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)initTabBar
{
    HomePageViewController *homePageViewController = [[HomePageViewController alloc] init];
    UINavigationController *homeNavigation = [[UINavigationController alloc] initWithRootViewController:homePageViewController];
    homeNavigation.navigationBar.translucent = NO;
    
    LearnMusicViewController *learnMusicViewController = [[LearnMusicViewController alloc] init];
    UINavigationController *learnMusicNavigation = [[UINavigationController alloc] initWithRootViewController:learnMusicViewController];
    learnMusicNavigation.navigationBar.translucent = NO;
    
    MusicCircleViewController *musicCircleViewController = [[MusicCircleViewController alloc] init];
    UINavigationController *musicCircleNavigation = [[UINavigationController alloc] initWithRootViewController:musicCircleViewController];
    musicCircleNavigation.navigationBar.translucent = NO;
    
    MineViewController *mineViewController = [[MineViewController alloc] init];
    UINavigationController *mineNavigation = [[UINavigationController alloc] initWithRootViewController:mineViewController];
    mineNavigation.navigationBar.translucent = NO;
    
    self.viewControllers = @[homeNavigation,learnMusicNavigation,musicCircleNavigation,mineNavigation];
    
    RDVTabBar *tabBar = self.tabBar;
    
    //背景颜色
    [tabBar setBackgroundColor:[UIColor whiteColor]];
    
    // 字体样式
    NSDictionary *unselectedFontDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
                                              [UIColor colorWithRed:100 / 255.0 green:100 / 255.0 blue:100 / 255.0 alpha:1.0], NSForegroundColorAttributeName, nil];
    NSDictionary *selectedFontDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
                                            [UIColor orangeColor], NSForegroundColorAttributeName, nil];
    
    
    RDVTabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
    //    [tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"tab_home_selected"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab_home"]];
    [tabBarItem1 setSelectedTitleAttributes:selectedFontDictionary];
    [tabBarItem1 setUnselectedTitleAttributes:unselectedFontDictionary];
    [tabBarItem1 setTitle:@"首页"];
    tabBarItem1.imagePositionAdjustment = UIOffsetMake(0, -2);
    
    RDVTabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
    //    [tabBarItem2 setFinishedSelectedImage:[UIImage imageNamed:@"tab_class_schedule_selected"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab_class_schedule"]];
    [tabBarItem2 setSelectedTitleAttributes:selectedFontDictionary];
    [tabBarItem2 setUnselectedTitleAttributes:unselectedFontDictionary];
    [tabBarItem2 setTitle:@"学音乐"];
    tabBarItem2.imagePositionAdjustment = UIOffsetMake(0, -2);
    
    RDVTabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2];
    //    [tabBarItem3 setFinishedSelectedImage:[UIImage imageNamed:@"tab_invite_selected"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab_invite"]];
    [tabBarItem3 setSelectedTitleAttributes:selectedFontDictionary];
    [tabBarItem3 setUnselectedTitleAttributes:unselectedFontDictionary];
    [tabBarItem3 setTitle:@"音乐圈"];
    tabBarItem3.imagePositionAdjustment = UIOffsetMake(0, -2);
    
    RDVTabBarItem *tabBarItem4 = [tabBar.items objectAtIndex:3];
    //    [tabBarItem4 setFinishedSelectedImage:[UIImage imageNamed:@"tab_invite_selected"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab_invite"]];
    [tabBarItem4 setSelectedTitleAttributes:selectedFontDictionary];
    [tabBarItem4 setUnselectedTitleAttributes:unselectedFontDictionary];
    [tabBarItem4 setTitle:@"我的"];
    tabBarItem4.imagePositionAdjustment = UIOffsetMake(0, -2);
    
    self.selectedIndex = 0;
}

//跳转之前判断登陆状态，如果需要登录，则弹出登录界面
- (BOOL)tabBarController:(RDVTabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
    
    
    
    return YES;
}

@end
